package com.ruoyi.quartz.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ManualAuditPage;
import com.ruoyi.system.service.ManualAuditPageService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects;

/*
 *  @author 雨安
 *  类名： ManualAuditPageController
 *  创建时间：2025/2/11
 */
@RestController
@RequestMapping("/ManualAuditPage")
public class ManualAuditPageController {

    @Resource
    private ManualAuditPageService manualAuditPageService;


    //查询
    @PostMapping("/get/ManualAuditPage")
    public AjaxResult getManualAuditPage(){
        System.out.println("我是测试sss");
        //创建分页对象
        Page<ManualAuditPage> page = new Page<>();
        //设置页码
        page.setCurrent(0);
        //设置行数
        page.setSize(10);
        //执行查询
        //执行查询
        manualAuditPageService.page(page,new LambdaQueryWrapper<ManualAuditPage>()
                //逻辑删除
                .eq(ManualAuditPage::getDeleteFlag,Boolean.FALSE)
        );
        page.setTotal(manualAuditPageService.count(new LambdaQueryWrapper<ManualAuditPage>()
                //逻辑删除
                .eq(ManualAuditPage::getDeleteFlag,Boolean.FALSE)
        ));
        //返回结果
        return AjaxResult.success(page);
    }

    //删除
    @PostMapping("/delete/ManualAuditPage/{id}")
    public AjaxResult deleteManualAuditPage(@PathVariable(value = "id")Long id){
        //调用Service层删除
        manualAuditPageService.update(null,new UpdateWrapper<ManualAuditPage>().lambda()
                //主键id
                .eq(ManualAuditPage::getId,id)
                //设置逻辑删除为 真
                .set(ManualAuditPage::getDeleteFlag,Boolean.TRUE)
        );
        //返回结果
        return AjaxResult.success("删除成功");
    }

    //增加
    @PostMapping("/insert/ManualAuditPage")
    public AjaxResult insertManualAuditPage(@RequestBody ManualAuditPage manualAuditPage){
        //设置默认值
        manualAuditPage.setCreateBy(SecurityUtils.getUsername());
        manualAuditPage.setCreateTime(new Date());
        manualAuditPage.setUpdateBy(SecurityUtils.getUsername());
        manualAuditPage.setUpdateTime(new Date());
        manualAuditPage.setDeleteFlag(Boolean.FALSE);
        //调用Service层删除
        manualAuditPageService.save(manualAuditPage);
        //返回结果
        return AjaxResult.success("新增成功");
    }

    //修改
    @PostMapping("/update/ManualAuditPage")
    public AjaxResult updateManualAuditPage(@RequestBody ManualAuditPage manualAuditPage){
        System.out.println(manualAuditPage);
        //设置默认值
        manualAuditPage.setUpdateTime(new Date());
        manualAuditPage.setDeleteFlag(Boolean.FALSE);
        //调用Service层删除
        manualAuditPageService.updateById(manualAuditPage);
        //返回结果
        return AjaxResult.success("修改成功");
    }
}